package com.longxiao.exception;

import com.longxiao.enums.Dictionary;
import com.longxiao.enums.ResultCode;
import com.longxiao.vo.CommResult;

public class LXException extends Exception {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7594256282624142953L;

	private String code;

	private String msg;


	public String getCode() {
		return code;
	}

	public LXException() {

	}

	public LXException(String code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public LXException(ResultCode resultCode, String language) {
		this.code = resultCode.getCode();
		if ("CN".equals(language)) {
			this.msg = resultCode.getCn();
		} else {
			this.msg = resultCode.getEn();
		}
	}

	public <T> CommResult<T> toResult(String language) {
		CommResult<T> result;
		if ("CN".equals(language)) {
			result = CommResult.failResult(code, Dictionary.getCn(code));
		} else {
			result = CommResult.failResult(code, Dictionary.getEn(code));
		}
		return result;
	}

	public String getMsg() {
		return msg;
	}
	
	@Override
	public String toString() {
		return "LXException [code=" + code + ", msg=" + msg + "]";
	}
	
}
